/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tv.pool.rn;

import java.math.BigDecimal;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import tv.global.excepciones.ExcepcionGeneralSistema;
import tv.global.excepciones.PreexistingEntityException;
import tv.global.excepciones.RollbackFailureException;
import tv.pool.dao.PoolDAO;
import tv.pool.modelo.Pool;
import tv.pool.modelo.ReservasPool;
import tv.pool.modelo.ReservasPoolPK;
import tv.venta.modelo.Cliente;

/**
 *
 * @author Claudio
 */
@Stateless
public class PoolRN {

    @EJB private PoolDAO poolDAO;

    public void guardar(Pool pool) throws PreexistingEntityException, RollbackFailureException, Exception{

        if(poolDAO.getObjeto(Pool.class, pool.getNroPool())==null){
            poolDAO.crear(pool);
        }else{
            poolDAO.editar(pool);
        }
    }

    public Pool getPool(Integer id){        
        return poolDAO.getObjeto(Pool.class, id );
    }

    public Pool refresh(Pool pool){
        return poolDAO.refresh(pool);
    }

    public void guardarReservar(ReservasPool r) throws ExcepcionGeneralSistema, PreexistingEntityException, RollbackFailureException, Exception{

        ReservasPoolPK idPK = new ReservasPoolPK(r.getNroPool(),r.getOrden(),r.getNroCuenta());

        if(poolDAO.getObjeto(ReservasPool.class, idPK)==null){
            poolDAO.crear(r);
        }else{
            poolDAO.editar(r);
        }

        
    }

    public List<Pool> getPoolesVisibles(){

        return poolDAO.getPoolesVisibles();
    }

    public List<Pool> getPoolesParaCerrar(){

        return poolDAO.getPoolesParaCerrar();
    }

    public List<Pool> getLista(){

        return poolDAO.getLista();
    }

    public BigDecimal getCantidadReservas(Pool pool) {
        return poolDAO.getCantidadReservas(pool);
    }

    public List<ReservasPool> getReservasPorCliente(Cliente cliente, String estado) {

        return poolDAO.getReservasPorCliente(cliente,estado);
    }

    public Integer getNumeroMaximoPool() {

        return poolDAO.getNumeroMaximoPool();
    }



    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
